package com.fbs.wowo.message.mapper;

import com.fbs.wowo.message.entity.UserMsg;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface UserMsgMapper {
    @Delete({
        "delete from user_msg",
        "where umid = #{umid,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String umid);

    @InsertProvider(type=UserMsgSqlProvider.class, method="insertSelective")
    int insertSelective(UserMsg record);

    @Select({
        "select",
        "umid, user_id, msg_type, entity_type, entity_id, status, create_time, msg_content",
        "from user_msg",
        "where umid = #{umid,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="umid", property="umid", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR),
        @Result(column="msg_type", property="msgType", jdbcType=JdbcType.TINYINT),
        @Result(column="entity_type", property="entityType", jdbcType=JdbcType.TINYINT),
        @Result(column="entity_id", property="entityId", jdbcType=JdbcType.VARCHAR),
        @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="msg_content", property="msgContent", jdbcType=JdbcType.LONGVARCHAR)
    })
    UserMsg selectByPrimaryKey(String umid);

    @UpdateProvider(type=UserMsgSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(UserMsg record);

    @Select({
            "select",
            "umid, user_id, msg_type, entity_type, entity_id, status, create_time, msg_content",
            "from user_msg",
            "where user_id = #{userId,jdbcType=VARCHAR}",
            "order by create_time desc"
    })
    @Results({
            @Result(column="umid", property="umid", jdbcType=JdbcType.VARCHAR, id=true),
            @Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR),
            @Result(column="msg_type", property="msgType", jdbcType=JdbcType.TINYINT),
            @Result(column="entity_type", property="entityType", jdbcType=JdbcType.TINYINT),
            @Result(column="entity_id", property="entityId", jdbcType=JdbcType.VARCHAR),
            @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="msg_content", property="msgContent", jdbcType=JdbcType.LONGVARCHAR)
    })
    List<UserMsg> findByUserId(String userId);
}